package com.effect.part1_ObjectCrateDestroy.item2;

/**
 * JavaBeans模式
 * Created by jon on 17-10-7.
 * ＪavaBean可能处于不一致的状态，
 * 类无法仅仅通过检验构造器参数的有效性来保证一致性
 *ＪavaBeans模式阻止了把类变成不可变的可能
 */
public class NutritionFacts_02 {
    //Parameters initialized  to default values(if any)
    private  int servingSize = -1;   //Required; no default value
    private  int servings    =-1;
    private  int calories    = 0;
    private  int fat         = 0;
    private  int sodium      = 0;
    private  int carbohydrate= 0;

    public NutritionFacts_02() {
    }
    //Setters

    public void setServingSize(int servingSize) {
        this.servingSize = servingSize;
    }

    public void setServings(int servings) {
        this.servings = servings;
    }

    public void setCalories(int calories) {
        this.calories = calories;
    }

    public void setFat(int fat) {
        this.fat = fat;
    }

    public void setSodium(int sodium) {
        this.sodium = sodium;
    }

    public void setCarbohydrate(int carbohydrate) {
        this.carbohydrate = carbohydrate;
    }

    public static void main(String[] args) {
        NutritionFacts_02 cocaCola = new NutritionFacts_02();
        cocaCola.setServingSize(240);
        cocaCola.setServings(8);
        cocaCola.setCalories(100);
        cocaCola.setSodium(35);
        cocaCola.setCarbohydrate(27);
    }
}
